package com.lmiot.xyclick.Activity;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.Html;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.google.gson.Gson;
import com.lkx.liandianqinew.R;
import com.lmiot.xyclick.App.MyApp;
import com.lmiot.xyclick.Auto.AutoUtils;
import com.lmiot.xyclick.Bean.SQL.AutoBean;
import com.lmiot.xyclick.Bean.SQL.AutoBeanSqlUtil;
import com.lmiot.xyclick.Bean.SQL.FriendBean;
import com.lmiot.xyclick.Bean.SQL.FriendBeanSqlUtil;
import com.lmiot.xyclick.Bean.ZxingBean;
import com.lmiot.xyclick.Util.Constants;
import com.lmiot.xyclick.Util.DataUtil;
import com.lmiot.xyclick.Util.DpUtil;
import com.lmiot.xyclick.Util.EditDialogUtil;
import com.lmiot.xyclick.Util.HttpUtilNew;
import com.lmiot.xyclick.Util.LayoutDialogUtil;
import com.lmiot.xyclick.Util.LogUtil;
import com.lmiot.xyclick.inteface.OnBasicListener;
import com.uuzuche.lib_zxing.activity.CaptureActivity;
import com.uuzuche.lib_zxing.activity.CodeUtils;
import com.xiaoyi.intentsdklibrary.Utils.ArrayGson;
import com.xiaoyi.intentsdklibrary.Utils.ImageUtil;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView;
import com.yanzhenjie.recyclerview.swipe.widget.DefaultItemDecoration;
import com.youyi.yypermissionlibrary.SDK.OnPerListener;
import com.youyi.yypermissionlibrary.SDK.YYPerUtils;
import com.youyi.yyviewsdklibrary.Dialog.util.ToastUtil;
import com.youyi.yyviewsdklibrary.LoadingDialog;
import com.youyi.yyviewsdklibrary.View.TitleBarView;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;

public class GroupControlListActivity extends BaseActivity implements View.OnClickListener {
    private static final String TAG = "GroupControlListActivity";
    private int REQUEST_CODE = 1893;
    private int REQUEST_IMAGE = 1894;
    private AutoAdapter mAdapter;
    LinearLayout mBtAll;
    LinearLayout mBtCancel;
    LinearLayout mBtExecute;
    LinearLayout mBtShare;
    LinearLayout mBtStop;
    private boolean mCheckAllFlag = false;
    public boolean mCheckFlag = false;
    private Set<String> mChoseIDSet = new HashSet();
    private Dialog mDialog;
    private List<FriendBean> mFgList;
    private HomeAdapter mHomeAdapter;
    LinearLayout mIdBottomLayout;
    TextView mIdEmptyLayout;
    EditText mIdSearchEdit;
    CardView mIdSearchLayout;
    TitleBarView mIdTitleBar;
    private LinearLayoutManager mLayoutManager;
    private String mPutAutoID;
    SwipeMenuRecyclerView mRecyclerView;
    LinearLayout mRecyclerViewLayout;
    private String mSearchName;
    private String mSearchNameAuto;

    /* access modifiers changed from: protected */
    @Override // android.support.v4.app.SupportActivity, com.lmiot.xyclick.Activity.BaseActivity, android.support.v7.app.AppCompatActivity, android.support.v4.app.FragmentActivity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_group_control_list);
        initView();
        this.mRecyclerView.addItemDecoration(new DefaultItemDecoration(getResources().getColor(R.color.transparent), -1, DpUtil.dip2px(MyApp.getContext(), 10.0f), 99));
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, 1, false);
        this.mLayoutManager = linearLayoutManager;
        this.mRecyclerView.setLayoutManager(linearLayoutManager);
        setEdit();
        this.mIdTitleBar.setOnItemClickListener(new TitleBarView.onItemClickListener() {
            /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass1 */

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onTitleClick(View view) {
            }

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onBackClick(View view) {
                GroupControlListActivity.this.finish();
            }

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onMenuClick(View view) {
                GroupControlListActivity.this.addMethod();
            }
        });
    }

    @Override // com.lmiot.xyclick.Activity.BaseActivity, android.support.v4.app.FragmentActivity
    public void onResume() {
        super.onResume();
        this.mIdTitleBar.setTitle(DataUtil.fgTitle);
        showListView();
    }

    private void setEdit() {
        this.mIdSearchEdit.addTextChangedListener(new TextWatcher() {
            /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass2 */

            public void afterTextChanged(Editable editable) {
            }

            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                GroupControlListActivity.this.mSearchName = charSequence.toString();
                if (!TextUtils.isEmpty(GroupControlListActivity.this.mSearchName)) {
                    ArrayList arrayList = new ArrayList();
                    if (GroupControlListActivity.this.mFgList != null && GroupControlListActivity.this.mFgList.size() > 0) {
                        for (FriendBean friendBean : GroupControlListActivity.this.mFgList) {
                            if (friendBean.getUserID().contains(GroupControlListActivity.this.mSearchName) || friendBean.getUserName().contains(GroupControlListActivity.this.mSearchName)) {
                                arrayList.add(friendBean);
                            }
                        }
                        if (GroupControlListActivity.this.mHomeAdapter != null) {
                            GroupControlListActivity.this.mHomeAdapter.setData(arrayList, GroupControlListActivity.this.mSearchName);
                        }
                    }
                } else if (GroupControlListActivity.this.mHomeAdapter != null) {
                    GroupControlListActivity.this.mHomeAdapter.setData(GroupControlListActivity.this.mFgList, null);
                }
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showListView() {
        if (DataUtil.fgID.equals("666")) {
            this.mFgList = FriendBeanSqlUtil.getInstance().searchAllUnGroup();
        } else {
            this.mFgList = FriendBeanSqlUtil.getInstance().searchAllByGroupID(DataUtil.fgID);
        }
        try {
            if (this.mFgList.size() == 0) {
                TextView textView = this.mIdEmptyLayout;
                if (textView != null) {
                    textView.setVisibility(View.VISIBLE);
                }
            } else {
                TextView textView2 = this.mIdEmptyLayout;
                if (textView2 != null) {
                    textView2.setVisibility(View.GONE);
                }
            }
            this.mCheckFlag = false;
            this.mChoseIDSet.clear();
            HomeAdapter homeAdapter = new HomeAdapter(this.mFgList);
            this.mHomeAdapter = homeAdapter;
            this.mRecyclerView.setAdapter(homeAdapter);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void addMethod() {
        ArrayList arrayList = new ArrayList();
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.tool_zxing, "拍照扫码", null));
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.chose_pic, "选择相册", null));
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.edit_time, "手动输入", null));
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.fg_remove, "导入其他设备", null));
        EditDialogUtil.getInstance().buttomMenuDialog(this, 6, arrayList, new EditDialogUtil.OnMenuClickListener() {
            /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass3 */

            @Override // com.lmiot.xyclick.Util.EditDialogUtil.OnMenuClickListener
            public void click(int i) {
                if (i == 0) {
                    YYPerUtils.camera(GroupControlListActivity.this, "拍照需要申请相机权限哦", new OnPerListener() {
                        /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass3.AnonymousClass1 */

                        @Override // com.youyi.yypermissionlibrary.SDK.OnPerListener
                        public void result(boolean z, String str) {
                            if (z) {
                                GroupControlListActivity.this.startActivityForResult(new Intent(GroupControlListActivity.this, CaptureActivity.class), GroupControlListActivity.this.REQUEST_CODE);
                                return;
                            }
                            ToastUtil.warning("缺少必要权限");
                        }
                    });
                } else if (i == 1) {
                    YYPerUtils.camera(GroupControlListActivity.this, "选择相册需要申请存储权限哦", new OnPerListener() {
                        /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass3.AnonymousClass2 */

                        @Override // com.youyi.yypermissionlibrary.SDK.OnPerListener
                        public void result(boolean z, String str) {
                            if (z) {
                                Intent intent = new Intent("android.intent.action.GET_CONTENT");
                                intent.addCategory("android.intent.category.OPENABLE");
                                intent.setType("image/*");
                                GroupControlListActivity.this.startActivityForResult(intent, GroupControlListActivity.this.REQUEST_IMAGE);
                                return;
                            }
                            ToastUtil.warning("缺少必要权限");
                        }
                    });
                } else if (i == 2) {
                    EditDialogUtil.getInstance().edit(GroupControlListActivity.this, 1, "添加设备", "请输入设备ID", "", new EditDialogUtil.EditMethod() {
                        /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass3.AnonymousClass3 */

                        @Override // com.lmiot.xyclick.Util.EditDialogUtil.EditMethod
                        public void edit(String str) {
                            GroupControlListActivity.this.addOrUpdate(new FriendBean(null, str, "--", "", "", "", DataUtil.fgID, DataUtil.fgTitle));
                        }
                    }, false);
                } else if (i == 3) {
                    EditDialogUtil.getInstance().choseFgDev(GroupControlListActivity.this, DataUtil.fgID, null, new EditDialogUtil.ShareEditMethod() {
                        /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass3.AnonymousClass4 */

                        @Override // com.lmiot.xyclick.Util.EditDialogUtil.ShareEditMethod
                        public void edit(Set<String> set) {
                            if (set != null && set.size() > 0) {
                                for (String str : set) {
                                    FriendBean searchByID = FriendBeanSqlUtil.getInstance().searchByID(str);
                                    if (searchByID != null) {
                                        if (!DataUtil.fgID.equals("6666")) {
                                            searchByID.setGroupID(DataUtil.fgID);
                                            searchByID.setGroupName(DataUtil.fgTitle);
                                        } else {
                                            searchByID.setGroupID("");
                                            searchByID.setGroupName("");
                                        }
                                        FriendBeanSqlUtil.getInstance().update(searchByID);
                                        ToastUtil.success("导入成功！");
                                        GroupControlListActivity.this.showListView();
                                    }
                                }
                            }
                        }
                    }, false);
                }
            }
        }, true, false);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void choseAutoDialog(final String str) {
//        if (str.equals(PushUtils.PUSH_ADMIN_TYPE_STOP)) {
//            LoadingDialog.show(this, LoadingDialog.DialogType.CENTER, true, "");
//            PushUtils.getInstance().pushList(PushTemplate.PushType.NoticAndExtra, this.mChoseIDSet, "收到指令", "停止自动化", PushUtils.getInstance().getAdminExtraString(PushUtils.PUSH_ADMIN_TYPE_STOP, ""), new OnBasicListener() {
//                /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass4 */
//
//                @Override // com.lmiot.xyclick.inteface.OnBasicListener
//                public void result(boolean z, String str) {
//                    LogUtil.d(GroupControlListActivity.TAG, "推送结果：isSuccess:" + z);
//                    LoadingDialog.hidden();
//                    if (z) {
//                        ToastUtil.success("操作成功!");
//                    } else {
//                        ToastUtil.err("操作失败!");
//                    }
//                }
//            });
//            return;
//        }
        try {
            Dialog dialog = this.mDialog;
            if (dialog != null && dialog.isShowing()) {
                this.mDialog.dismiss();
            }
            this.mSearchNameAuto = "";
            Dialog createSysDailog = LayoutDialogUtil.createSysDailog(this, R.layout.dialog_chose_groud_auto);
            this.mDialog = createSysDailog;
            TextView textView = (TextView) createSysDailog.findViewById(R.id.id_title);
            EditText editText = (EditText) this.mDialog.findViewById(R.id.id_search_edit);
            ListView listView = (ListView) this.mDialog.findViewById(R.id.id_listview);
            List<AutoBean> arrayList = new ArrayList<>();
//            if (str.equals(PushUtils.PUSH_TYPE_SHARE)) {
//                textView.setText("请选择一个自动化下发");
//                arrayList = AutoBeanSqlUtil.getInstance().searchAll();
//            } else if (str.equals(PushUtils.PUSH_ADMIN_TYPE_RUN)) {
//                textView.setText("请选择一个自动化执行");
//                arrayList = AutoBeanSqlUtil.getInstance().searchAll();
//            }
            if (arrayList.size() == 0) {
                this.mDialog.dismiss();
                ToastUtil.warning(str.equals("share") ? "请先添加一个自动化！" : "请先添加一个定时的自动化！");
                return;
            }
            Collections.sort(arrayList, new Comparator<AutoBean>() {
                /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass5 */

                public int compare(AutoBean autoBean, AutoBean autoBean2) {
                    return Collator.getInstance(Locale.CHINA).compare((Object) autoBean.getAutoName(), (Object) autoBean2.getAutoName());
                }
            });
            AutoAdapter autoAdapter = new AutoAdapter(arrayList);
            this.mAdapter = autoAdapter;
            listView.setAdapter((ListAdapter) autoAdapter);
            setEditAuto(editText, arrayList);
            ((TextView) this.mDialog.findViewById(R.id.tv_cancel)).setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass6 */

                public void onClick(View view) {
                    GroupControlListActivity.this.mDialog.dismiss();
                }
            });
            ((TextView) this.mDialog.findViewById(R.id.tv_sure)).setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass7 */

                public void onClick(View view) {
                    if (TextUtils.isEmpty(GroupControlListActivity.this.mPutAutoID)) {
                        ToastUtil.warning("请先选一个自动化！");
                        return;
                    }
                    GroupControlListActivity.this.mDialog.dismiss();
                    LoadingDialog.show(GroupControlListActivity.this, LoadingDialog.DialogType.CENTER, true, "");
                    HttpUtilNew.getInstance().upLoadAutoFile(GroupControlListActivity.this.mPutAutoID, new OnBasicListener() {
                        /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass7.AnonymousClass1 */

                        @Override // com.lmiot.xyclick.inteface.OnBasicListener
                        public void result(boolean z, String str) {
                            if (z) {
                                AutoBean searchByID = AutoBeanSqlUtil.getInstance().searchByID(GroupControlListActivity.this.mPutAutoID);
//                                PushUtils instance = PushUtils.getInstance();
//                                PushTemplate.PushType pushType = PushTemplate.PushType.NoticAndExtra;
                                Set<String> set = GroupControlListActivity.this.mChoseIDSet;
//                                instance.pushList(pushType, set, "收到分享自动化指令", "自动化名称：" + searchByID.getAutoName(), PushUtils.getInstance().getAdminExtraString(str, GroupControlListActivity.this.mPutAutoID), new OnBasicListener() {
//                                    /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass7.AnonymousClass1.AnonymousClass1 */
//
//                                    @Override // com.lmiot.xyclick.inteface.OnBasicListener
//                                    public void result(boolean z, String str) {
//                                        LogUtil.d(GroupControlListActivity.TAG, "推送结果：isSuccess:" + z);
//                                        LoadingDialog.hidden();
//                                        if (z) {
//                                            ToastUtil.success("操作成功!");
//                                        } else {
//                                            ToastUtil.err("操作失败!");
//                                        }
//                                    }
//                                });
//                                return;
                            }
                            ToastUtil.err("操作失败，请检查网络!");
                        }
                    });
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void setEditAuto(EditText editText, final List<AutoBean> list) {
        editText.addTextChangedListener(new TextWatcher() {
            /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass8 */

            public void afterTextChanged(Editable editable) {
            }

            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                GroupControlListActivity.this.mSearchNameAuto = charSequence.toString();
                if (!TextUtils.isEmpty(GroupControlListActivity.this.mSearchNameAuto)) {
                    List arrayList = new ArrayList();
                    arrayList = list;
                    if (list != null && list.size() > 0) {
                        for (AutoBean autoBean : list) {
                            if (autoBean.getAutoName().contains(GroupControlListActivity.this.mSearchNameAuto)) {
                                arrayList.add(autoBean);
                            }
                        }
                        if (GroupControlListActivity.this.mAdapter != null) {
                            GroupControlListActivity.this.mAdapter.setData(arrayList, GroupControlListActivity.this.mSearchNameAuto);
                        }
                    }
                } else if (GroupControlListActivity.this.mAdapter != null) {
                    GroupControlListActivity.this.mAdapter.setData(list, null);
                }
            }
        });
    }

    public void cancelEdit() {
        this.mCheckFlag = false;
        this.mIdBottomLayout.setVisibility(View.GONE);
        HomeAdapter homeAdapter = this.mHomeAdapter;
        if (homeAdapter != null) {
            homeAdapter.notifyDataSetChanged();
        }
    }

    private void initView() {
        this.mIdTitleBar = (TitleBarView) findViewById(R.id.id_title_bar);
        this.mIdEmptyLayout = (TextView) findViewById(R.id.id_empty_layout);
        this.mIdSearchEdit = (EditText) findViewById(R.id.id_search_edit);
        this.mIdSearchLayout = (CardView) findViewById(R.id.id_search_layout);
        this.mRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recyclerView);
        this.mRecyclerViewLayout = (LinearLayout) findViewById(R.id.recyclerView_layout);
        this.mBtCancel = (LinearLayout) findViewById(R.id.bt_cancel);
        this.mBtShare = (LinearLayout) findViewById(R.id.bt_share);
        this.mBtExecute = (LinearLayout) findViewById(R.id.bt_execute);
        this.mBtStop = (LinearLayout) findViewById(R.id.bt_stop);
        this.mBtAll = (LinearLayout) findViewById(R.id.bt_all);
        this.mIdBottomLayout = (LinearLayout) findViewById(R.id.id_bottom_layout);
        this.mBtCancel.setOnClickListener(this);
        this.mBtShare.setOnClickListener(this);
        this.mBtExecute.setOnClickListener(this);
        this.mBtStop.setOnClickListener(this);
        this.mBtAll.setOnClickListener(this);
    }

    public void onClick(View view) {
        int id = view.getId();
        if (id != R.id.bt_share) {
            if (id != R.id.bt_stop) {
                switch (id) {
                    case R.id.bt_all /*{ENCODED_INT: 2131296328}*/:
                        boolean z = !this.mCheckAllFlag;
                        this.mCheckAllFlag = z;
                        HomeAdapter homeAdapter = this.mHomeAdapter;
                        if (homeAdapter != null) {
                            homeAdapter.checkAll(z);
                            return;
                        }
                        return;
                    case R.id.bt_cancel /*{ENCODED_INT: 2131296329}*/:
                        cancelEdit();
                        return;
                    case R.id.bt_execute /*{ENCODED_INT: 2131296330}*/:
                        if (this.mChoseIDSet.size() == 0) {
                            ToastUtil.warning("请先选择一个设备！");
                            return;
                        }
//                        choseAutoDialog(PushUtils.PUSH_ADMIN_TYPE_RUN);
                        cancelEdit();
                        return;
                    default:
                        return;
                }
            } else if (this.mChoseIDSet.size() == 0) {
                ToastUtil.warning("请先选择一个设备！");
            } else {
//                choseAutoDialog(PushUtils.PUSH_ADMIN_TYPE_STOP);
                cancelEdit();
            }
        } else if (this.mChoseIDSet.size() == 0) {
            ToastUtil.warning("请先选择一个设备！");
        } else {
//            choseAutoDialog(PushUtils.PUSH_TYPE_SHARE);
            cancelEdit();
        }
    }

    /* access modifiers changed from: private */
    public class AutoAdapter extends BaseAdapter {
        private List<AutoBean> autoList;

        public Object getItem(int i) {
            return null;
        }

        public long getItemId(int i) {
            return 0;
        }

        public AutoAdapter(List<AutoBean> list) {
            this.autoList = list;
        }

        public int getCount() {
            List<AutoBean> list = this.autoList;
            if (list == null) {
                return 0;
            }
            return list.size();
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            final AutoBean autoBean = this.autoList.get(i);
            View inflate = View.inflate(GroupControlListActivity.this, R.layout.item_chose_groud_auto, null);
            ImageView imageView = (ImageView) inflate.findViewById(R.id.id_checked);
            ImageView imageView2 = (ImageView) inflate.findViewById(R.id.id_unchecked);
            TextView textView = (TextView) inflate.findViewById(R.id.id_name);
            String autoID = autoBean.getAutoID();
            String autoName = autoBean.getAutoName();
            if (TextUtils.isEmpty(GroupControlListActivity.this.mSearchNameAuto)) {
                textView.setText(autoName);
            } else {
                String str = GroupControlListActivity.this.mSearchNameAuto;
                textView.setText(Html.fromHtml(autoName.replace(str, "<font color='#FF0000'>" + GroupControlListActivity.this.mSearchNameAuto + "</font>")));
            }
            if (TextUtils.isEmpty(GroupControlListActivity.this.mPutAutoID)) {
                imageView.setVisibility(View.GONE);
                imageView2.setVisibility(View.VISIBLE);
            } else if (GroupControlListActivity.this.mPutAutoID.equals(autoID)) {
                imageView.setVisibility(View.VISIBLE);
                imageView2.setVisibility(View.GONE);
            } else {
                imageView.setVisibility(View.GONE);
                imageView2.setVisibility(View.VISIBLE);
            }
            inflate.setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AutoAdapter.AnonymousClass1 */

                public void onClick(View view) {
                    GroupControlListActivity.this.mPutAutoID = autoBean.getAutoID();
                    AutoAdapter.this.notifyDataSetChanged();
                }
            });
            return inflate;
        }

        public void setData(List<AutoBean> list, String str) {
            this.autoList = list;
            GroupControlListActivity.this.mSearchNameAuto = str;
            notifyDataSetChanged();
        }
    }

    public class HomeAdapter extends RecyclerView.Adapter {
        private List<FriendBean> mList;

        @Override // android.support.v7.widget.RecyclerView.Adapter
        public int getItemViewType(int i) {
            return 0;
        }

        public HomeAdapter(List<FriendBean> list) {
            this.mList = list;
        }

        @Override // android.support.v7.widget.RecyclerView.Adapter
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
            return new HomeViewHolder(View.inflate(GroupControlListActivity.this, R.layout.item_group_cardview, null));
        }

        @Override // android.support.v7.widget.RecyclerView.Adapter
        public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
            final HomeViewHolder homeViewHolder = (HomeViewHolder) viewHolder;
            final FriendBean friendBean = this.mList.get(i);
            final String userID = friendBean.getUserID();
            String str = friendBean.getUserName() + "";
            if (TextUtils.isEmpty(GroupControlListActivity.this.mSearchName)) {
                homeViewHolder.tvID.setText(userID);
                homeViewHolder.tvName.setText(str);
            } else {
                homeViewHolder.tvID.setText(Html.fromHtml(userID.replace(GroupControlListActivity.this.mSearchName, "<font color='#FF0000'>" + GroupControlListActivity.this.mSearchName + "</font>")));
                homeViewHolder.tvName.setText(Html.fromHtml(str.replace(GroupControlListActivity.this.mSearchName, "<font color='#FF0000'>" + GroupControlListActivity.this.mSearchName + "</font>")));
            }
            if (GroupControlListActivity.this.mCheckFlag) {
                homeViewHolder.more.setVisibility(View.GONE);
                if (GroupControlListActivity.this.mChoseIDSet.contains(userID)) {
                    homeViewHolder.imgChecked.setVisibility(View.VISIBLE);
                    homeViewHolder.imgUnChecked.setVisibility(View.GONE);
                } else {
                    homeViewHolder.imgChecked.setVisibility(View.GONE);
                    homeViewHolder.imgUnChecked.setVisibility(View.VISIBLE);
                }
                homeViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                    /* class com.lmiot.xyclick.Activity.GroupControlListActivity.HomeAdapter.AnonymousClass1 */

                    public void onClick(View view) {
                        if (GroupControlListActivity.this.mChoseIDSet.contains(userID)) {
                            GroupControlListActivity.this.mChoseIDSet.remove(userID);
                            homeViewHolder.imgChecked.setVisibility(View.GONE);
                            homeViewHolder.imgUnChecked.setVisibility(View.VISIBLE);
                            return;
                        }
                        GroupControlListActivity.this.mChoseIDSet.add(userID);
                        homeViewHolder.imgChecked.setVisibility(View.VISIBLE);
                        homeViewHolder.imgUnChecked.setVisibility(View.GONE);
                    }
                });
            } else {
                homeViewHolder.more.setVisibility(View.VISIBLE);
                homeViewHolder.imgChecked.setVisibility(View.GONE);
                homeViewHolder.imgUnChecked.setVisibility(View.GONE);
            }
            homeViewHolder.more.setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.Activity.GroupControlListActivity.HomeAdapter.AnonymousClass2 */

                public void onClick(View view) {
                    GroupControlListActivity.this.showUserMoreDialog(friendBean);
                }
            });
        }

        @Override // android.support.v7.widget.RecyclerView.Adapter
        public int getItemCount() {
            List<FriendBean> list = this.mList;
            if (list == null) {
                return 0;
            }
            return list.size();
        }

        public void setData(List<FriendBean> list, String str) {
            this.mList = list;
            GroupControlListActivity.this.mSearchName = str;
            notifyDataSetChanged();
        }

        public void checkAll(boolean z) {
            if (z) {
                for (FriendBean friendBean : this.mList) {
                    GroupControlListActivity.this.mChoseIDSet.add(friendBean.getUserID());
                }
            } else {
                GroupControlListActivity.this.mChoseIDSet.clear();
            }
            notifyDataSetChanged();
        }

        private class HomeViewHolder extends RecyclerView.ViewHolder {
            ImageView imgChecked;
            ImageView imgUnChecked;
            ImageView more;
            TextView tvID;
            TextView tvName;

            public HomeViewHolder(View view) {
                super(view);
                this.tvName = (TextView) view.findViewById(R.id.id_user_name);
                this.tvID = (TextView) view.findViewById(R.id.id_user_id);
                this.more = (ImageView) view.findViewById(R.id.id_more);
                this.imgChecked = (ImageView) view.findViewById(R.id.id_checked);
                this.imgUnChecked = (ImageView) view.findViewById(R.id.id_unchecked);
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showUserMoreDialog(final FriendBean friendBean) {
        ArrayList arrayList = new ArrayList();
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.edit_time, "备注设备", null));
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.edit_time, "修改ID", null));
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.auto_share, "分享数据", null));
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.del, "删除设备", null));
        EditDialogUtil.getInstance().buttomMenuDialog(this, 4, arrayList, new EditDialogUtil.OnMenuClickListener() {
            /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass9 */

            @Override // com.lmiot.xyclick.Util.EditDialogUtil.OnMenuClickListener
            public void click(int i) {
                if (i == 0) {
                    EditDialogUtil.getInstance().edit(GroupControlListActivity.this, 1, "备注设备", "请输入备注名称", friendBean.getUserName(), new EditDialogUtil.EditMethod() {
                        /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass9.AnonymousClass1 */

                        @Override // com.lmiot.xyclick.Util.EditDialogUtil.EditMethod
                        public void edit(String str) {
                            friendBean.setUserName(str);
                            GroupControlListActivity.this.addOrUpdate(friendBean);
                        }
                    }, false);
                } else if (i == 1) {
                    EditDialogUtil.getInstance().edit(GroupControlListActivity.this, 1, "修改ID", "请输入ID", friendBean.getUserID(), new EditDialogUtil.EditMethod() {
                        /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass9.AnonymousClass2 */

                        @Override // com.lmiot.xyclick.Util.EditDialogUtil.EditMethod
                        public void edit(String str) {
                            friendBean.setUserID(str);
                            GroupControlListActivity.this.addOrUpdate(friendBean);
                        }
                    }, false);
                } else if (i == 2) {
                    GroupControlListActivity.this.mChoseIDSet.clear();
                    GroupControlListActivity.this.mChoseIDSet.add(friendBean.getUserID());
//                    GroupControlListActivity.this.choseAutoDialog(PushUtils.PUSH_TYPE_SHARE);
                } else if (i == 3) {
                    LayoutDialogUtil.showSureDialog(GroupControlListActivity.this, "温馨提示", "您是否要删除当前设备？", true, true, "取消", "确定", new LayoutDialogUtil.OnResultClickListener() {
                        /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass9.AnonymousClass3 */

                        @Override // com.lmiot.xyclick.Util.LayoutDialogUtil.OnResultClickListener
                        public void result(boolean z) {
                            if (z) {
                                FriendBeanSqlUtil.getInstance().delByID(friendBean.getUserID());
                                GroupControlListActivity.this.showListView();
                            }
                        }
                    });
                }
            }
        }, false, false);
    }

    /* access modifiers changed from: protected */
    @Override // android.support.v4.app.FragmentActivity
    public void onActivityResult(int i, int i2, Intent intent) {
        Bundle extras;
        super.onActivityResult(i, i2, intent);
        if (i == this.REQUEST_CODE) {
            if (intent != null && (extras = intent.getExtras()) != null) {
                if (extras.getInt(CodeUtils.RESULT_TYPE) == 1) {
                    reslove(extras.getString(CodeUtils.RESULT_STRING));
                } else if (extras.getInt(CodeUtils.RESULT_TYPE) == 2) {
                    ToastUtil.err("解析二维码失败");
                }
            }
        } else if (i == this.REQUEST_IMAGE && intent != null) {
            try {
                CodeUtils.analyzeBitmap(ImageUtil.getImageAbsolutePath(this, intent.getData()), new CodeUtils.AnalyzeCallback() {
                    /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass10 */

                    @Override // com.uuzuche.lib_zxing.activity.CodeUtils.AnalyzeCallback
                    public void onAnalyzeSuccess(Bitmap bitmap, String str) {
                        GroupControlListActivity.this.reslove(str);
                    }

                    @Override // com.uuzuche.lib_zxing.activity.CodeUtils.AnalyzeCallback
                    public void onAnalyzeFailed() {
                        ToastUtil.err("解析二维码失败");
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void reslove(String str) {
        try {
            ZxingBean zxingBean = (ZxingBean) new Gson().fromJson(str, ZxingBean.class);
            if (zxingBean != null) {
                String type = zxingBean.getType();
                char c = 65535;
                int hashCode = type.hashCode();
                if (hashCode != 1347678425) {
                    if (hashCode == 1348271861) {
                        if (type.equals(Constants.ZXING_TYPE_USER)) {
                            c = 0;
                        }
                    }
                } else if (type.equals(Constants.ZXING_TYPE_AUTO)) {
                    c = 1;
                }
                if (c == 0) {
                    addOrUpdate(new FriendBean(null, zxingBean.getUserID(), zxingBean.getUserBrand(), zxingBean.getUserBrand(), zxingBean.getUserModel(), "", DataUtil.fgID, DataUtil.fgTitle));
                    ToastUtil.success("设备添加成功！");
                } else if (c == 1) {
                    AutoUtils.downAutoData(this, zxingBean.getUserID(), zxingBean.getAutoID());
                }
            } else if (str.startsWith("#Friend#")) {
                ZxingBean zxingBean2 = (ZxingBean) new ArrayGson().fromJson(str.replace("#Friend#", ""), ZxingBean.class);
                if (zxingBean2 != null) {
                    addOrUpdate(new FriendBean(null, zxingBean2.getUserID(), zxingBean2.getUserBrand(), zxingBean2.getUserBrand(), zxingBean2.getUserModel(), "", DataUtil.fgID, DataUtil.fgTitle));
                    ToastUtil.warning("设备添加成功！");
                }
            } else {
                EditDialogUtil.getInstance().sureDialog(this, "二维码识别结果", str, 0, new EditDialogUtil.setOnSureListener() {
                    /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass11 */

                    @Override // com.lmiot.xyclick.Util.EditDialogUtil.setOnSureListener
                    public void sureClick(boolean z) {
                    }
                }, false);
            }
        } catch (Exception e) {
            e.printStackTrace();
            if (str.startsWith("#Friend#")) {
                ZxingBean zxingBean3 = (ZxingBean) new ArrayGson().fromJson(str.replace("#Friend#", ""), ZxingBean.class);
                if (zxingBean3 != null) {
                    addOrUpdate(new FriendBean(null, zxingBean3.getUserID(), zxingBean3.getUserBrand(), zxingBean3.getUserBrand(), zxingBean3.getUserModel(), "", DataUtil.fgID, DataUtil.fgTitle));
                    ToastUtil.success("设备添加成功！");
                    return;
                }
                return;
            }
            EditDialogUtil.getInstance().sureDialog(this, "二维码识别结果", str, 0, new EditDialogUtil.setOnSureListener() {
                /* class com.lmiot.xyclick.Activity.GroupControlListActivity.AnonymousClass12 */

                @Override // com.lmiot.xyclick.Util.EditDialogUtil.setOnSureListener
                public void sureClick(boolean z) {
                }
            }, false);
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void addOrUpdate(FriendBean friendBean) {
        FriendBeanSqlUtil.getInstance().add(friendBean);
        showListView();
    }
}
